<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Class_Assess extends WxHomeController
{

	function __construct()
	{
		parent::__construct();
		$this->sidebar = "Index";
		$this->load->model("Class_model");
		$this->load->library('ProjectService/attend_service');
		$this->load->model("Attend_model");
		$this->load->model("Attend_img_model");
		$this->load->library('ProjectService/class_service');
		$this->load->model("Admin_model");
		$this->date = date('Y-m-d', time());
		$this->month = date('m', time());//当前学期
		// $this->month = date('m', '1661740784');
	}
	// function Index($attend_id,$teacher_code=false,$class_name=false){

	// 	if($attend_id==0){
	// 		$result=$this ->attend_service->getAttendData(0);
	// 		$result['is_add']=0;
	// 		$result['teacher_code']=$teacher_code;
	// 		// $result['no_class']=false;
	// 		$result['teacher_detail']=$this -> Admin_model->get_single(array("id"=>$teacher_code));	
	// 		$date=date('Y-m-d',time());			
	// 		$month=date('m',time());			
	// 		// if($result['class_detail']){
	// 			// if($result['class_detail']['classroom']){
	// 			// 	$result['class_detail']['classroom']=urldecode($classroom);
	// 			// }else{
	// 			// 	$result['class_detail']['classroom']='';
	// 			// }
	// 		// }else{
	// 		// 	$result['no_class']=true;
	// 		// }
	// 		if($class_name){
	// 			$class=$this->Class_model->get_single(array('id'=>$class_name));
	// 			$result['class_detail']['class_name']=$class['name'];
	// 		}
	// 		if($month==9 || $month==10 || $month==11 || $month==12 || $month==1){
	// 			$year=date('Y',time());
	// 			$year_last=date('Y',time())+1;
	// 			$result['class_detail']['semester']='第一学期';	
	// 			$result['class_detail']['academic_year']=strval($year.'-'.$year_last);			
	// 		}else if($month==2 || $month==3 || $month==4 || $month==5 || $month==6 || $month==7 || $month==8){
	// 			$year=date('Y',time())-1;
	// 			$year_last=date('Y',time());
	// 			$semester='第一学期';	
	// 			$result['class_detail']['academic_year']=strval($year.'-'.$year_last);	
	// 			$result['class_detail']['semester']='第二学期';
	// 		}
	// 		$this->load->view('home/class_assess',$result);
	// 	}else{
	// 		$result=$this->attend_service->getAttendData($attend_id);
	// 		// foreach ($result['attend_record'] as $k => $v) {
	// 		// 	$result['attend_record'][$k]['time']=date('h:m:s',$result['attend_record'][$k]['time']);				
	// 		// }
	// 		$result['is_add']=$attend_id;
	// 		$this->load->view('home/class_assess',$result);
	// 	}

	// }
	function Index($soure,$type, $attend_id, $teacher_id = false)
	{
		$_SESSION[SESS_ASSESS]['soure'] = $soure;
		$_SESSION[SESS_ASSESS]['cc_type'] = $type;
		if ($teacher_id) {
			$data = $this->Admin_model->get_single(array('id' => $teacher_id));
			$result['teacher_detail'] = $data;
		}
		$role = explode(',', $_SESSION[SESS_USER_HOME]['sub_role_id']);
		array_push($role, $_SESSION[SESS_USER_HOME]['role_id']);
		$role = array_merge(array_filter($role));



		if ($attend_id == 0) {
			$result = $this->attend_service->getAttendData(0, false, false, $type);
			unset($result['attend']['listen_time']);
			$result['is_add'] = 0;
			// $date = date('Y-m-d', time());
			// $month = date('m', time());
			if ($this->month == 9 || $this->month == 10 || $this->month == 11 || $this->month == 12 || $this->month == 1) {
				if ($this->month == 1) {
					$year = date('Y', time()) - 1;
					$year_last = date('Y', time());
				} else {
					$year = date('Y', time());
					$year_last = date('Y', time()) + 1;
				}
				// $year=date('Y',time());
				// $year_last=date('Y',time())+1;
				$result['class_detail']['semester'] = '第一学期';
				$result['class_detail']['academic_year'] = strval($year . '-' . $year_last);
			} else if ($this->month == 2 || $this->month == 3 || $this->month == 4 || $this->month == 5 || $this->month == 6 || $this->month == 7 || $this->month == 8) {
				$year = date('Y', time()) - 1;
				$year_last = date('Y', time());
				// $semester = '第一学期';
				$result['class_detail']['academic_year'] = strval($year . '-' . $year_last);
				$result['class_detail']['semester'] = '第二学期';
			}
			if (isset($_GET['next'])) {
				$result['next'] = $_GET['next'];
			}

			$result['cc_type'] = $type;
			//获取新版课程类型 
			$this->load->model("Select_model");
			$result1 = $this->Select_model->get_list(array('type' => SelectType::CourseType[XPHEnum::Value], 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
			foreach ($result1 as $k => $v) {
				if ($type == ($k + 1)) {
					$_SESSION[SESS_ASSESS]['classtype'] =  trim($v['option']);
					// array_push($data['class_type'], trim($v['option']));
				}
			}

			if (in_array(WebRole::SchoolLeader[XPHEnum::Value], $role) || in_array(WebRole::UnitLeader[XPHEnum::Value], $role) || in_array(WebRole::CadreUnitLeader[XPHEnum::Value], $role)) {
				$result['is_mr_ldgb'] = 1;
			 }else{
				$result['is_mr_ldgb'] = 0;
			 }

			if ($type == 1) {
				// $_SESSION[SESS_ASSESS]['classtype'] = '理论课';
				$this->load->view('home/class_assess2', $result);
			}else if ($type == 2) {
				// $_SESSION[SESS_ASSESS]['classtype'] = '实训课';
				$this->load->view('home/class_assess3', $result);
			}else if ($type == 3) {
				// $_SESSION[SESS_ASSESS]['classtype'] = '思政课';
				$this->load->view('home/class_assess4', $result);
			}else if ($type == 4) {
				// $_SESSION[SESS_ASSESS]['classtype'] = '体育课';
				$this->load->view('home/class_assess5', $result);
			}else{
				$this->load->view('home/class_assess2', $result);
			}
			// $this->load->view('home/class_assess2',$result);
		} else {

			$result = $this->attend_service->getAttendData($attend_id, false, false, $type);

			$result['is_add'] = $attend_id;
			if ($result['attend']['type'] == AttendType::School[XPHEnum::Value]) {
				$result['role_index'] = 0;
			} else if ($result['attend']['type'] == AttendType::Unit[XPHEnum::Value]) {
				$result['role_index'] = 1;
			}
			if ($teacher_id) {
				$data = $this->Admin_model->get_single(array('id' => $teacher_id));
				$result['teacher_detail'] = $data;
			}
			if (isset($_GET['next'])) {
				$result['next'] = $_GET['next'];
			}
			$result['cc_type'] = $type;

			//获取新版课程类型 
			$this->load->model("Select_model");
			$result1 = $this->Select_model->get_list(array('type' => SelectType::CourseType[XPHEnum::Value], 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
			foreach ($result1 as $k => $v) {
				if ($type == ($k + 1)) {
					$_SESSION[SESS_ASSESS]['classtype'] =  trim($v['option']);
					// array_push($data['class_type'], trim($v['option']));
				}
			}

			if (in_array(WebRole::SchoolLeader[XPHEnum::Value], $role) || in_array(WebRole::UnitLeader[XPHEnum::Value], $role) || in_array(WebRole::CadreUnitLeader[XPHEnum::Value], $role)) {
				$result['is_mr_ldgb'] = 1;
			 }else{
				$result['is_mr_ldgb'] = 0;
			 }

			if ($type == 1) {
				// $_SESSION[SESS_ASSESS]['classtype'] = '理论课';
				$this->load->view('home/class_assess2', $result);
			}else if ($type == 2) {
				// $_SESSION[SESS_ASSESS]['classtype'] = '实训课';
				$this->load->view('home/class_assess3', $result);
			} else if ($type == 3)  {
				// $_SESSION[SESS_ASSESS]['classtype'] = '思政课';
				$this->load->view('home/class_assess4', $result);
			}else if ($type == 4)  {
				// $_SESSION[SESS_ASSESS]['classtype'] = '体育课';
				$this->load->view('home/class_assess5', $result);
			}else{
				$this->load->view('home/class_assess2', $result);
			}
			// $this->load->view('home/class_assess2',$result);
		}
	}

	function getSelect($type)
	{
		// $this -> load -> model("Select_model");
		// $result=$this -> Select_model -> get_list(array('type'=>SelectType::CourseType[XPHEnum::Value],'status'=>CommonStatus::UnDeleted[XPHEnum::Value]));
		// $data['class_type']=array();
		// foreach ($result as $k => $v) {
		// 	array_push($data['class_type'],$v['option']);
		// }
		//获取新版课程类型 
		$this->load->model("Select_model");
		if ($type == 1) {
			$result = $this->Select_model->get_list(array('type' => SelectType::CourseType[XPHEnum::Value], 'option' => '理论课', 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
			$data['class_type'] = array();
			foreach ($result as $k => $v) {
				array_push($data['class_type'], trim($v['option']));
			}
		} else {
			$result = $this->Select_model->get_list(array('type' => SelectType::CourseType[XPHEnum::Value], 'option' => '实训课', 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
			$data['class_type'] = array();
			foreach ($result as $k => $v) {
				array_push($data['class_type'], trim($v['option']));
			}
		}

		//获取旧版课程类型
		$result1 = $this->Select_model->get_list(array('type' => 11, 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));


		$data['class_type_old'] = array();
		foreach ($result1 as $k => $v) {
			array_push($data['class_type_old'], trim($v['option']));
		}

		// 听课类别-0723
		$result = $this->Select_model->get_list(array('type' => SelectType::ListenType[XPHEnum::Value], 'status' => CommonStatus::UnDeleted[XPHEnum::Value]));
		$data['listen_type'] = array();
		foreach ($result as $k => $v) {
			array_push($data['listen_type'], $v['option']);
		}
		$data['title'] = (new Title)->getAllOneD();
		$data['age_groups'] = (new AgeGroups)->getAllOneD();
		$data['teachers_attribute'] = (new TeachersAttribute)->getAllOneD();
		// 获取身份选项

		$data['type'] = array();
		$role = explode(',', $_SESSION[SESS_USER_HOME]['sub_role_id']);
		array_push($role, $_SESSION[SESS_USER_HOME]['role_id']);
		$role = array_merge(array_filter($role));
		if (in_array(WebRole::SchoolSupervisor[XPHEnum::Value], $role)) {
			// unset($data['type'][0]);
			// array_splice($data['type'],0,1);  
			array_push($data['type'], AttendType::School[XPHEnum::Caption]);
		}
		if (in_array(WebRole::UnitSupervisor[XPHEnum::Value], $role)) {
			// unset($data['type'][1]);
			// array_splice($data['type'],1,1);  
			array_push($data['type'], AttendType::Unit[XPHEnum::Caption]);
		}
		if (in_array(WebRole::OutsideSupervisor[XPHEnum::Value], $role)) {
			// unset($data['type'][1]);
			// array_splice($data['type'],1,1);  
			array_push($data['type'], AttendType::Outside[XPHEnum::Caption]);
		}
		if (in_array(WebRole::Teacher[XPHEnum::Value], $role)) {
			array_push($data['type'], AttendType::Teacher[XPHEnum::Caption]);
		}

		if (in_array(WebRole::SchoolLeader[XPHEnum::Value], $role) || in_array(WebRole::UnitLeader[XPHEnum::Value], $role) || in_array(WebRole::CadreUnitLeader[XPHEnum::Value], $role)) {
			array_push($data['type'], AttendType::UnitLeader[XPHEnum::Caption]);
		}

		if (in_array(WebRole::MajorUnitLeader[XPHEnum::Value], $role)) {
			array_push($data['type'], AttendType::MajorUnitLeader[XPHEnum::Caption]);
		}
		//超级管理员
		if (in_array(WebRole::Admin[XPHEnum::Value], $role)) {
			$data['type'] = (new AttendType)->getAllOneD();
		}

		// 获取开课单位
		// $date=date('Y-m-d',time());			
		// $month=date('m',time());
		// if($month==9 || $month==10 || $month==11 || $month==12){
		// 	$year=date('Y',time());
		// 	$year_last=date('Y',time())+1;
		// 	$default_academic_year=strval($year.'-'.$year_last);			
		// }else if($month==1 || $month==2 || $month==3 || $month==4 || $month==5 || $month==6 || $month==7 || $month==8){
		// 	$year=date('Y',time())-1;
		// 	$year_last=date('Y',time());
		// 	$default_academic_year=strval($year.'-'.$year_last);	
		// }
		// $connar['items']="course_units";
		// $connar['where']=$this->sqlLikeEscape('elective_lesson_no like "%??%" and course_units is not null',array($default_academic_year));
		// $connar['groupby']="course_units";
		// $data['course_units']=array_column($this->Class_model->get_list_full($connar), 'course_units');
		// foreach($data['course_units'] as $k=>$v){
		// 	if(!$v){
		// 		unset($data['course_units'][$k]);
		// 	}
		// }
		// $data['course_units'] = array_merge($data['course_units']);

		//获取开课单位
		$data['course_units'] = (new AdminDeptList)->getRemark()[1];


		//获取分数下拉列表
		$result = $this->attend_service->getAttendData(0, false, false, $type);
		
		$data['teaching_content_score'] = array();
		$data['student_status_score'] = array();
		$data['teaching_implementation_score'] = array();
		// $score=array();
		// // var_dump($result);
		// // exit;
		// foreach ($result['attend_teaching_content'] as $k => $v) {
		// 	// foreach ($v['score'] as $k1 => $v1) {
		// 	// 	array_push($data['teaching_content_score'][$k],)
		// 	// }
		// 	for($i=1;$i<=$v['score'];$i++){
		// 		$score=array($i-1=>$i);
		// 		if($i==0){
		// 			$t=array_merge_recursive($score);
		// 		}else{
		// 			array_push($score,$i);
		// 		}

		// 	}
			
		foreach ($result['attend_teaching_content'] as $k => $v) {
			$score = array();
			// for($i=1;$i<=$result['attend_teaching_content'][$k]['score'];$i++){
			$score[$k] = $v['score'];
			// }
			foreach ($score as $k2 => $v2) {
				array_push($score, $v2);
			}
			$data['teaching_content_score'][$k] = $score;
		}

		

		foreach ($result['attend_student_status'] as $k => $v) {
			$score = array();
			// for($i=1;$i<=$result['attend_student_status'][$k]['score'];$i++){
			$score[$k] = $v['score'];
			// }
			foreach ($score as $k2 => $v2) {
				array_push($score, $v2);
			}
			$data['student_status_score'][$k] = $score;
		}

		foreach ($result['attend_teaching_implementation'] as $k => $v) {
			$score = array();
			// for($i=1;$i<=$result['attend_teaching_implementation'][$k]['score'];$i++){
			$score[$k] = $v['score'];
			// }
			foreach ($score as $k2 => $v2) {
				array_push($score, $v2);
			}
			$data['teaching_implementation_score'][$k] = $score;
		}

//		 pri($data);

		exit(retJson('返回下拉框选项', true, $data));
	}
	// function IndexAdd($teacher_name,$classroom,$classname){	
	//     $result['teacher_name']=$_POST['teacher_name'];
	//     $result['classroom']=$_POST['classroom'];
	//     $result['classname']=$_POST['classname'];
	// 	$this->load->view('home/class_assess',$result);
	// }

	function showClass($class_id)
	{
		$data = $this->class_service->getClassById($class_id);

		$data['start_time'] = date('H:i:s', $data['start_time']);
		$data['end_time'] = date('H:i:s', $data['end_time']);
		// $this->load->view('home/showClass',$data);
		exit(retJson("课程数据", true, $data));
	}


	function ClassIndex()
	{
		// $connar['items']="DISTINCT(db_class.classroom)";
		// $result['classroom'] = $this -> Class_model ->get_list_full($connar);

		// $connar['items']="DISTINCT(db_class.name) classname";
		// $result['classname'] = $this -> Class_model ->get_list_full($connar);

		// $connar['items']="DISTINCT(db_admin.username) teacher_name,db_class.teacher_id";
		// $connar['join']=array("db_admin","db_admin.id=db_class.teacher_id");
		// $result['teacher'] = $this -> Class_model ->get_list_full($connar);
		// $connar1['items']="db_class.*,db_admin.username teacher_name";
		// $connar1['join']=array("db_admin","db_admin.id=db_class.teacher_id");		
		// $result['detail']=$this -> Class_model ->get_list_full($connar1);
		// $connar2['items']="max(end_time) max_week";
		// $data=$this-> Class_model->get_single_full($connar2);
		// $result['max_week']=$data['max_week'];
		$data['class_name'] = '';
		$data['class_code'] = '';
		$data['teacher_name'] = '';
		$data['class_id'] = '';
		$data['teacher_id'] = '';
		if (isset($_GET['class_name'])) {
			$data['class_name'] = urldecode($_GET['class_name']);
		}
		if (isset($_GET['teacher_name'])) {
			$data['teacher_name'] = urldecode($_GET['teacher_name']);
		}
		if (isset($_GET['class_id'])) {
			$data['class_id'] = urldecode($_GET['class_id']);
		}
		if (isset($_GET['teacher_id'])) {
			$data['teacher_id'] = urldecode($_GET['teacher_id']);
		}
		$this->load->view("home/check_class", $data);
	}
	function ClassTeacherList()
	{
		$connar['items'] = "db_admin.username teacher_name,db_class.*";
		$connar['join'] = array("db_admin", "db_admin.id=db_class.teacher_id", 'right1');
		$result = $this->Class_model->get_list_full($connar);
		exit(retJson('返回教师列表', true, $result));
	}
	function SearchClass()
	{
		$connar['items'] = "db_class.*,a.username teacher_name";
		$connar['join'] = array('db_admin a', 'a.id=db_class.teacher_id');
		$connar['where'] = '1=1 and teacher_id=20080024';
		if (isset($_POST['teacher_id'])) {
			$connar['where'] .= $this->sqlEscape(' and db_class.teacher_id=??', array($_POST['teacher_id']));
		}
		if (isset($_POST['date']) && $_POST['date'] > -1) {
			$date = strtotime($_POST['date']);
			$connar['where'] .= $this->sqlEscape(' and db_class.created=??', array($date));
		}
		$result = $this->Class_model->get_list_full($connar);
		exit(retJson('查询成功', true, $result));
	}

	function getClass()
	{
		// $class=$this->class_service->getClass(time(),true);
		$connar['items'] = "db_class.*,db_admin.username";
		$connar['join'] = array("db_admin", "db_admin.id=db_class.teacher_id");
		$class = $this->Class_model->get_list_full($connar);
		exit(retJson("课程数据", true, $class));
	}




	function searchClassChange($is_default = false)
	{
		if ($is_default) {
			$connar1['items'] = "id,username";
			$connar1['where'] = $this->sqlEscape("role_id=?? or find_in_set(??,sub_role_id)", array(WebRole::Teacher[XPHEnum::Value], WebRole::Teacher[XPHEnum::Value]));
			$connar1['orderby'] = "CONVERT(username USING GBK) ASC ";
			$result['teacher_list'] = $this->Admin_model->get_list_full($connar1);
		} else {
			// $date = date('Y-m-d', time());
			// $month = date('m', time());
			if ($this->month == 9 || $this->month == 10 || $this->month == 11 || $this->month == 12 || $this->month == 1) {
				if ($this->month == 1) {
					$year = date('Y', time()) - 1;
					$year_last = date('Y', time());
				} else {
					$year = date('Y', time());
					$year_last = date('Y', time()) + 1;
				}
				// $year=date('Y',time());
				// $year_last=date('Y',time())+1;
				$default_academic_year = strval($year . '-' . $year_last);
			} else if ($this->month == 2 || $this->month == 3 || $this->month == 4 || $this->month == 5 || $this->month == 6 || $this->month == 7 || $this->month == 8) {
				$year = date('Y', time()) - 1;
				$year_last = date('Y', time());
				$default_academic_year = strval($year . '-' . $year_last);
			}
			$connar['items'] = "db_class.id,db_class.name,db_class.classroom,db_class.classname,db_class.teacher_id,db_admin.username teacher_name,sksj";
			$connar['where'] = $this->sqlLikeEscape('elective_lesson_no like "%??%"', array($default_academic_year));
			$connar['join'] = array("db_admin", "db_admin.usercode=db_class.teacher_id");
			if (isset($_POST['teacher_name']) && $_POST['teacher_name'] != '选择授课教师') {
				$connar['where'] .= $this->sqlEscape(" and db_admin.username=?? ", array($_POST['teacher_name']));
			}
			if (isset($_POST['date']) && $_POST['date'] != '') {
				$connar['where'] .= $this->sqlEscape(" and start_time<=?? and end_time>=??", array($_POST['date'], $_POST['date']));
			}
			if (isset($_POST['weekday']) && $_POST['weekday'] != '') {
				$connar['where'] .= $this->sqlLikeEscape(" and sksj like '%??%' ", array($_POST['weekday']));
			}
			if (isset($_POST['term']) && $_POST['term'] != '') {
				if ($_POST['term'] == '第一学期') {
					$term = '1';
				} else {
					$term = '2';
				}
				$connar['where'] .= $this->sqlEscape(" and SUBSTRING(elective_lesson_no, 12,1)=?? ", array($term));
			}
			$result['list'] = $this->Class_model->get_list_full($connar);
			foreach ($result['list'] as $k => $v) {
				$sksj[$k] = explode(';', $v['sksj']);
				$classroom[$k] = explode(';', $v['classroom']);
				foreach ($sksj[$k] as $k1 => $v1) {
					// if($_POST['weekday']!=''){
					// 	if(strpos($v1,$_POST['weekday']) !== false){
					$result['list'][$k]['classroom_d'] = $classroom[$k][$k1];
					// 	}
					// }else{
					// 	$result['list'][$k]['classroom_d']=$classroom[$k][$k1];	
					// }						
				}
			}
		}
		exit(retJson("查询成功", true, $result));
	}

	function checkClass()
	{
		// $date = date('Y-m-d', time());
		// $month = date('m', time());
		if ($this->month == 9 || $this->month == 10 || $this->month == 11 || $this->month == 12 || $this->month == 1) {
			if ($this->month == 1) {
				$year = date('Y', time()) - 1;
				$year_last = date('Y', time());
			} else {
				$year = date('Y', time());
				$year_last = date('Y', time()) + 1;
			}
			// $year=date('Y',time());
			// $year_last=date('Y',time())+1;
			$default_academic_year = strval($year . '-' . $year_last);
		} else if ($this->month == 2 || $this->month == 3 || $this->month == 4 || $this->month == 5 || $this->month == 6 || $this->month == 7 || $this->month == 8) {
			$year = date('Y', time()) - 1;
			$year_last = date('Y', time());
			$default_academic_year = strval($year . '-' . $year_last);
		}
		// 获取教师
		$connar['where'] = $this->sqlLikeEscape('elective_lesson_no like "%??%" and name="??" and teacher_id=?? and classname="??" ', array($default_academic_year, $_POST['name'], $_POST['teacher_id'], $_POST['classname']));
		$data = $this->Class_model->get_single_full($connar);
		if ($data) {
			exit(retJson("查询成功", true, $data));
		} else {
			exit(retJson("不存在该课程", false));
		}
	}
	function diffBetweenTwoDays($day1, $day2)
	{
		$second1 = strtotime($day1);
		$second2 = strtotime($day2);

		if ($second1 < $second2) {
			$tmp = $second2;
			$second2 = $second1;
			$second1 = $tmp;
		}
		return ($second1 - $second2) / 86400;
	}
	function checkSubrole()
	{
		$this->load->model("Admin_model");
		$connar['items'] = 'id,usercode,username,role_id,sub_role_id';
		$connar['where'] = $this->sqlEscape("id=?? ", array($_SESSION[SESS_USER_HOME]['id']));
		$result = $this->Admin_model->get_single_full($connar);
		// var_dump($this->db->last_query());
		// exit();
		if ($result) {
			$_SESSION[SESS_USER_HOME] = $result;
			if ($_SESSION[SESS_USER_HOME]['sub_role_id'] != null || $_SESSION[SESS_USER_HOME]['sub_role_id'] != '') {
				$data['check_role'] = 1;
				$html = "<select id='sub_role' class='input'><option value='0' checked>请选择反馈身份</option>";
				$sub_role = explode(',', $result['sub_role_id']);
				array_push($sub_role, $result['role_id']);
				$count = 0;
				foreach ($sub_role as $k => $v) {
					if ($v == WebRole::SchoolSupervisor[XPHEnum::Value] || $v == WebRole::UnitSupervisor[XPHEnum::Value]) {
						$count++;
					}
				}
				if ($count > 1) {
					foreach ($sub_role as $k => $v) {
						$role_name = (new WebRole)->show($v);
						if ($v == WebRole::SchoolSupervisor[XPHEnum::Value] || $v == WebRole::UnitSupervisor[XPHEnum::Value]) {
							$html = $html . '<option value=' . $v . '>' . $role_name . '</option>';
						}
					}
					$html = $html . "</select>";
					$data['html'] = $html;
					exit(retJson("请选择反馈身份！", true, $data));
				}
			}
		}
	}
	function saveAttend($attend_id = 0)
	{


		$is_submit = $this->Attend_model->get_single(array('id' => $attend_id));
		if ($is_submit['status'] == AttendStatus::Submit[XPHEnum::Value]) {
			exit(retJson('已提交无法修改', false));
		}
		unset($_POST['attend_img']);
		$formdata = $_POST;


		
		//教师听课只能保存,无法提交
		if ($formdata['role'] == AttendType::Teacher[XPHEnum::Caption] && $formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {
			exit(retJson('教师听课无法提交', false));
		}


		$data = $this->Class_model->get_single(array('id' => $formdata['class_id']));
		$data1 = $this->Admin_model->get_single(array('id' => $formdata['teacher_id']));
		$data2 = $this->Admin_model->get_single(array('id' => $_SESSION[SESS_USER_HOME]['id']));
		$class_id = $data['id'];

		// if($formdata['sub_role']==0){
		// 	$Error['error']=3;
		// 	exit(retJson('请选择反馈身份！',false,$Error));
		// }else{
		// 	$type=$formdata['sub_role'];
		// }		
		// if($type==WebRole::SchoolSupervisor[XPHEnum::Value]){
		// 	$type=AttendType::School[XPHEnum::Value];
		// }else if($type==WebRole::UnitSupervisor[XPHEnum::Value]){
		// 	$type=AttendType::Unit[XPHEnum::Value];
		// // }
		if ($formdata['role'] == AttendType::School[XPHEnum::Caption]) {
			$type = AttendType::School[XPHEnum::Value];
		} else if ($formdata['role'] == AttendType::Unit[XPHEnum::Caption]) {
			$type = AttendType::Unit[XPHEnum::Value];
		} else if ($formdata['role'] == AttendType::Outside[XPHEnum::Caption]) {
			$type = AttendType::Outside[XPHEnum::Value];
		} else if ($formdata['role'] == AttendType::Teacher[XPHEnum::Caption]) {
			$type = AttendType::Teacher[XPHEnum::Value];
		} else if ($formdata['role'] == AttendType::UnitLeader[XPHEnum::Caption]) {
			$type = AttendType::UnitLeader[XPHEnum::Value];
		} else if ($formdata['role'] == AttendType::MajorUnitLeader[XPHEnum::Caption]) {
			$type = AttendType::MajorUnitLeader[XPHEnum::Value];
		}
		// $serial_no=$formdata['attend1'];
		$academic_year = $formdata['attend2']; //学年
		$semester = $formdata['attend3']; //学期
		// $class_name=$data['name'];
		// $class_type=$data['type'];
		// $teacher_name=$data1['username'];
		// $title=$data1['title'];
		// $dept_name=$data1['dept_name'];
		// $age_groups=$data1['age_groups'];
		// $teachers_attribute=$data1['teachers_attribute'];
		// $listen_name=$data2['username'];
		// $listen_address=$data['classroom'];
		// $course_units=$data['course_units'];
		$listen_class = $formdata['attend4']; //听课班级
		$advice = $formdata['attend5']; //意见或建议

		$class_name = $formdata['class_name']; //课程名称,课程内容
		$class_type = $formdata['class_type']; //课程类型
		$teacher_name = $formdata['teacher_name']; //授课教师
		$teacher_code = $formdata['teacher_code']; //授课教师工号
		$title = $formdata['title']; //教师职称
		$dept_name = $formdata['dept_name']; //教师所属单位
		// $age_groups=$formdata['age_groups'];
		$age_groups = 0;
		$teachers_attribute = $formdata['teachers_attribute']; //教师属性
		$listen_name = $data2['username']; //听课姓名
		$listen_address = $formdata['listen_address']; //听课地址
		$course_units = $formdata['course_units']; //开课单位
		$class_id = $formdata['class_id']; //课程id
		$listen_type = $formdata['listen_type']; //听课类型
		$teachingLevel = $formdata['teachingLevel']; //教学能力分数
		$teachingEffect = $formdata['teachingEffect']; //学生状况分数 // 2025 xin
		
		//提交的时候验证
		if ($formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {
			if ($formdata['course_units'] == '' || $formdata['listen_time'] == ''  || $formdata['listen_time'] == '0' || $formdata['class_name'] == '' || $formdata['teacher_name'] == '' || $formdata['dept_name'] == '' || $formdata['title'] == '' || $formdata['teachers_attribute'] == '' || $formdata['class_type'] == '' || $formdata['attend4'] == '' || $formdata['listen_address'] == '' || $formdata['role'] == '' || $formdata['listen_type'] == '') {
				exit(retJson("请填写完整的课程信息", false, 1));
			}
		}


		

		// $age_groups=(new AgeGroups)->show($age_groups);
		// $teachers_attribute=(new TeachersAttribute)->show($teachers_attribute);
		//教学水平

		if ($formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {

			foreach ($teachingLevel as $k => $v) {
				if ($v == '请打分' || $v == '' || $v == '0') {
					$Error['error'] = 1;
					exit(retJson("请选择完整的教学能力分数", false, $Error));
				}
			}
		}

		$teachingLevel_rank = array('0', '0', '0', '0', '0');
		$teachingLevel_count = 0;
		foreach ($teachingLevel as $k => $v) {
			if ($v != '请打分' || $v != '' || $v != '0') {
				$teachingLevel_count = $teachingLevel_count + $teachingLevel[$k];
			}
		}

		if ($teachingLevel_count >= 90) {
			$teachingLevel_rank[0] = '1';
		} else if ($teachingLevel_count >= 80 and $teachingLevel_count < 90) {
			$teachingLevel_rank[1] = '1';
		} else if ($teachingLevel_count >= 70 and $teachingLevel_count < 80) {
			$teachingLevel_rank[2] = '1';
		} else if ($teachingLevel_count >= 60 and $teachingLevel_count < 70) {
			$teachingLevel_rank[3] = '1';
		} else if ($teachingLevel_count < 60 && $teachingLevel_count > 0) {
			$teachingLevel_rank[4] = '1';
		}


		//教学效果


		
		if ($formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {

			
			foreach ($teachingEffect as $k => $v) {
				if ($v == '0' || $v == '' || $v == '0') {
					
					
					$Error['error'] = 2;
					if($_SESSION[SESS_ASSESS]['cc_type'] ==3){
						exit(retJson("请选择完整的课堂效果分数", false, $Error));
					}else{
						exit(retJson("请选择完整的学生状况分数", false, $Error));
					}
					
				}
			}
		}

		$teachingEffect_rank = array('0', '0', '0', '0', '0');
		$teachingEffect_count = 0;
		foreach ($teachingEffect as $k => $v) {
			if ($v != '0' || $v != '') {
				$teachingEffect_count = $teachingEffect_count + $teachingEffect[$k];
			}
		}
		if ($teachingEffect_count >= 90) {
			$teachingEffect_rank[0] = '1';
		} else if ($teachingEffect_count >= 80 and $teachingEffect_count < 90) {
			$teachingEffect_rank[1] = '1';
		} else if ($teachingEffect_count >= 70 and $teachingEffect_count < 80) {
			$teachingEffect_rank[2] = '1';
		} else if ($teachingEffect_count >= 60 and $teachingEffect_count < 70) {
			$teachingEffect_rank[3] = '1';
		} else if ($teachingEffect_count < 60 && $teachingEffect_count > 0) {
			$teachingEffect_rank[4] = '1';
		}
		// 20210901听课取消
		/* if(isset($formdata['teachingReadiness'])){
			$teachingReadiness=$formdata['teachingReadiness'];
			}else{
				$teachingReadiness=array();
			}
			$studentsNorm=$formdata['studentsNorm'];
			$classroom_facilities=$formdata['classroom_facilities'];
			$classroom_environmental=$formdata['classroom_environmental']; */

		// foreach ((new ClassroomFacilities)->getAll()as $k => $v) {
		// 	if($classroom_facilities==$v[XPHEnum::Value]){
		// 		$classroom_facilities_item=$v[XPHEnum::Value];
		// 	}
		// }
		// foreach ((new ClassroomEnvironmental)->getAll()as $k => $v) {
		// 	if($classroom_environmental==$v[XPHEnum::Value]){
		// 		$classroom_environmental_item=$v[XPHEnum::Value];
		// 	}
		// }
		//      $attend_record=$formdata['attend_record'];
		//      $recordcount=$formdata['recordcount'];
		//      $attend_record_value=array();
		//      $k =0;
		//      for ($i=1;$i<=$recordcount;$i++){
		// //$item = array('time'=>$attend_record[$i-1].",activity"=>$attend_record[$i].",commentary"=>$attend_record[$i+1].")";			
		//      	$item['time'] =strtotime($attend_record[$k]);
		//      	$item['activity'] =$attend_record[$k+1];
		//      	$item['commentary'] =$attend_record[$k+2];
		//      	array_push($attend_record_value, $item);
		//      	$k+=3;
		//      }

		// if(!isset($this->NOTXSS_POST['attend_img'])){
		// 	exit(retJson("请上传图片",false));
		// }
		// foreach ($this->NOTXSS_POST['attend_img'] as $k => $v) {
		// 	if($v!=null ||$v!=''){
		// 		$attend_img=$this->NOTXSS_POST['attend_img'];
		// 	}else{
		// 		exit(retJson("请上传图片",false));
		// 	}
		// }

		// $attend_img_value=array();
		// if(isset($this->NOTXSS_POST['attend_img'])){
		// 	$attend_img=$this->NOTXSS_POST['attend_img'];
		// 	for ($i=0;$i<=count($attend_img)-1;$i++){
		// 		$item['img'] = $attend_img[$i];
		// 		if (checkStringIsBase64($item['img'])) {

		// 			$checkRet = uploadImg($item['img'], 'attend_img');
		// 			if (!$checkRet['status']) {
		// 				exit(toRetJson($checkRet));
		// 			}
		// 			$data['img']=$checkRet["v"];

		// 		} else {
		// 			exit(retJson('上传的图片格式不正确！', false));
		// 		}
		// 		array_push($attend_img_value, $data); 
		// 	}
		// }
		// 听课记录(附件)
		if (isset($_SESSION[SESS_ASSESS]['img1']) && $_SESSION[SESS_ASSESS]) {
			$attend_img1 =  $_SESSION[SESS_ASSESS]['img1'];
			$attend_img1_value = array();
			foreach ($attend_img1 as $ks => $vs) {
				$attend_img1_value[$ks]['img'] = $vs;
			}
		} else {
			$attend_img1_value = array();
		}

		// 意见或建议(附件)
		if (isset($_SESSION[SESS_ASSESS]['img2']) && $_SESSION[SESS_ASSESS]) {
			$attend_img2 =  $_SESSION[SESS_ASSESS]['img2'];
			$attend_img2_value = array();
			foreach ($attend_img2 as $ks => $vs) {
				$attend_img2_value[$ks]['img'] = $vs;
			}
		} else {
			$attend_img2_value = array();
		}

		// 学生常态(附件)
		if (isset($_SESSION[SESS_ASSESS]['img3']) && $_SESSION[SESS_ASSESS]) {
			$attend_img3 =  $_SESSION[SESS_ASSESS]['img3'];
			$attend_img3_value = array();
			foreach ($attend_img3 as $ks => $vs) {
				$attend_img3_value[$ks]['img'] = $vs;
			}
		} else {
			$attend_img3_value = array();
		}

		$is_add = $formdata['is_add'];
		if ($formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {
			$status = AttendStatus::Submit[XPHEnum::Value];
		} else {
			$status = AttendStatus::Save[XPHEnum::Value];
		}
		// 0415新需求教学准备开展情况可选
		/* foreach ($formdata['attend_teaching_readiness_content'] as $k => $v) {
			if(!isset($teachingReadiness[$k])){
				$teachingReadiness[$k]='';
			}
		}
		// 0415新需求学生常态可选
		foreach ($formdata['attend_students_norm_item'] as $k => $v) {
			if(!isset($studentsNorm[$k])){
				$studentsNorm[$k]='';
			}
		} */

		
		if ($_SESSION[SESS_ASSESS]['cc_type'] == 2) {
			$param = array(
				'attend' => array(
					'class_id' => $class_id,
					'listen_id' => $_SESSION[SESS_USER_HOME]['id'],
					'type' => $type,
					// 'serial_no'=>$serial_no,
					'academic_year' => $academic_year, //学年
					'semester' => $semester, //学期
					'class_name' => $class_name,
					'class_type' => $class_type,
					'cc_type' => $_SESSION[SESS_ASSESS]['cc_type'],
					'teacher_name' => $teacher_name,
					'teacher_code' => $teacher_code,
					'title' => $title,
					'dept_name' => $dept_name,
					'age_groups' => $age_groups,
					'teachers_attribute' => $teachers_attribute,
					'listen_name' => $listen_name,
					'listen_time' => $formdata['listen_time'],
					'listen_address' => $listen_address,
					'course_units' => $course_units,
					'listen_class' => $listen_class,
					// 'classroom_facilities'=>$classroom_facilities_item,
					// 'classroom_environmental'=>$classroom_environmental_item,
					'advice' => $advice,
					'teaching_level_score' => $teachingLevel_count,
					'teaching_effect_score' => $teachingEffect_count,
					'status' => $status,
					// 0415新增总分 教学70%+学生30%
					'score' => ($teachingLevel_count + $teachingEffect_count),
					// 0723新增听课类型
					'listen_type' => $listen_type
				),
				'attends_teaching_content' => array(
					0 => array('key_index' => $formdata['attends_teaching_index'][0], 'list_id' => $formdata['attends_teaching_list_id'][0], 'content' => $formdata['attends_teaching_content'][0], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[0]),
					1 => array('key_index' => $formdata['attends_teaching_index'][1], 'list_id' => $formdata['attends_teaching_list_id'][1], 'content' => $formdata['attends_teaching_content'][1], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[1]),
					2 => array('key_index' => $formdata['attends_teaching_index'][2], 'list_id' => $formdata['attends_teaching_list_id'][2], 'content' => $formdata['attends_teaching_content'][2], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[2]),
					3 => array('key_index' => $formdata['attends_teaching_index'][3], 'list_id' => $formdata['attends_teaching_list_id'][3], 'content' => $formdata['attends_teaching_content'][3], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[3]),
					4 => array('key_index' => $formdata['attends_teaching_index'][4], 'list_id' => $formdata['attends_teaching_list_id'][4], 'content' => $formdata['attends_teaching_content'][4], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[4])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_index'][2],'list_id'=>$formdata['attend_teaching_list_id'][2],'content'=>$formdata['attend_teaching_content'][2],'score'=>$formdata['attend_teaching_score'][0],'get_score'=>$teachingLevel[2])
				),
				'attend_teaching_level' => array(
					0 => array('item' => $formdata['attend_teaching_level_item'][0], 'remark' => $formdata['attend_teaching_level_remark'][0], 'is_check' => $teachingLevel_rank[0]),
					1 => array('item' => $formdata['attend_teaching_level_item'][1], 'remark' => $formdata['attend_teaching_level_remark'][1], 'is_check' => $teachingLevel_rank[1]),
					2 => array('item' => $formdata['attend_teaching_level_item'][2], 'remark' => $formdata['attend_teaching_level_remark'][2], 'is_check' => $teachingLevel_rank[2]),
					3 => array('item' => $formdata['attend_teaching_level_item'][3], 'remark' => $formdata['attend_teaching_level_remark'][3], 'is_check' => $teachingLevel_rank[3]),
					4 => array('item' => $formdata['attend_teaching_level_item'][4], 'remark' => $formdata['attend_teaching_level_remark'][4], 'is_check' => $teachingLevel_rank[4])
				),
				'attend_student_status' => array(
					0 => array('key_index' => $formdata['attend_student_status_index'][0], 'list_id' => $formdata['attend_student_status_list_id'][0], 'content' => $formdata['attend_student_status'][0], 'score' => $formdata['attend_student_status_score'][0], 'get_score' => $teachingEffect[0])
					// ,
					// 1=>array('key_index'=>$formdata['attend_student_status_index'][1],'list_id'=>$formdata['attend_student_status_list_id'][1],'content'=>$formdata['attend_student_status'][1],'score'=>$formdata['attend_student_status_score'][1],'get_score'=>$teachingEffect[1]),
					// 2=>array('key_index'=>$formdata['attend_student_status_index'][2],'list_id'=>$formdata['attend_student_status_list_id'][2],'content'=>$formdata['attend_student_status'][2],'score'=>$formdata['attend_student_status_score'][2],'get_score'=>$teachingEffect[2]),
					// 3=>array('key_index'=>$formdata['attend_student_status_index'][3],'list_id'=>$formdata['attend_student_status_list_id'][3],'content'=>$formdata['attend_student_status'][3],'score'=>$formdata['attend_student_status_score'][3],'get_score'=>$teachingEffect[3]),
					// 4=>array('key_index'=>$formdata['attend_student_status_index'][4],'list_id'=>$formdata['attend_student_status_list_id'][4],'content'=>$formdata['attend_student_status'][4],'score'=>$formdata['attend_student_status_score'][4],'get_score'=>$teachingEffect[4]),
					// 5=>array('key_index'=>$formdata['attend_student_status_index'][5],'list_id'=>$formdata['attend_student_status_list_id'][5],'content'=>$formdata['attend_student_status'][5],'score'=>$formdata['attend_student_status_score'][5],'get_score'=>$teachingEffect[5])
				),
				'attend_teaching_effect' => array(
					0 => array('item' => $formdata['attend_student_status_item'][0], 'remark' => $formdata['attend_student_status_remark'][0], 'is_check' => $teachingEffect_rank[0])
					// ,
					// 1=>array('item'=>$formdata['attend_student_status_item'][1],'remark'=>$formdata['attend_student_status_remark'][1],'is_check'=>$teachingEffect_rank[1]),
					// 2=>array('item'=>$formdata['attend_student_status_item'][2],'remark'=>$formdata['attend_student_status_remark'][2],'is_check'=>$teachingEffect_rank[2]),
					// 3=>array('item'=>$formdata['attend_student_status_item'][3],'remark'=>$formdata['attend_student_status_remark'][3],'is_check'=>$teachingEffect_rank[3]),
					// 4=>array('item'=>$formdata['attend_student_status_item'][4],'remark'=>$formdata['attend_student_status_remark'][4],'is_check'=>$teachingEffect_rank[4])
				),
				/* 'attend_teaching_readiness'=>array(
					0=>array('item'=>$formdata['attend_teaching_readiness_content'][0],'option'=>$formdata['attend_teaching_readiness_option'][0],'check_value'=>$teachingReadiness[0]),
					1=>array('item'=>$formdata['attend_teaching_readiness_content'][1],'option'=>$formdata['attend_teaching_readiness_option'][1],'check_value'=>$teachingReadiness[1]),
					2=>array('item'=>$formdata['attend_teaching_readiness_content'][2],'option'=>$formdata['attend_teaching_readiness_option'][2],'check_value'=>$teachingReadiness[2]),
					3=>array('item'=>$formdata['attend_teaching_readiness_content'][3],'option'=>$formdata['attend_teaching_readiness_option'][3],'check_value'=>$teachingReadiness[3]),
					4=>array('item'=>$formdata['attend_teaching_readiness_content'][4],'option'=>$formdata['attend_teaching_readiness_option'][4],'check_value'=>$teachingReadiness[4]),
					5=>array('item'=>$formdata['attend_teaching_readiness_content'][5],'option'=>$formdata['attend_teaching_readiness_option'][5],'check_value'=>$teachingReadiness[5]),
					6=>array('item'=>$formdata['attend_teaching_readiness_content'][6],'option'=>$formdata['attend_teaching_readiness_option'][6],'check_value'=>$teachingReadiness[6]),
					7=>array('item'=>$formdata['attend_teaching_readiness_content'][7],'option'=>$formdata['attend_teaching_readiness_option'][7],'check_value'=>$teachingReadiness[7]),
					8=>array('item'=>$formdata['attend_teaching_readiness_content'][8],'option'=>$formdata['attend_teaching_readiness_option'][8],'check_value'=>$teachingReadiness[8]),
					9=>array('item'=>$formdata['attend_teaching_readiness_content'][9],'option'=>$formdata['attend_teaching_readiness_option'][9],'check_value'=>$teachingReadiness[9]),
					10=>array('item'=>$formdata['attend_teaching_readiness_content'][10],'option'=>$formdata['attend_teaching_readiness_option'][10],'check_value'=>$teachingReadiness[10]),
					11=>array('item'=>$formdata['attend_teaching_readiness_content'][11],'option'=>$formdata['attend_teaching_readiness_option'][11],'check_value'=>$teachingReadiness[11])
				),
				'attend_students_norm'=>array(
					0=>array('item'=>$formdata['attend_students_norm_item'][0],'check_value'=>$studentsNorm[0]),
					1=>array('item'=>$formdata['attend_students_norm_item'][1],'check_value'=>$studentsNorm[1]),
					2=>array('item'=>$formdata['attend_students_norm_item'][2],'check_value'=>$studentsNorm[2]),
					3=>array('item'=>$formdata['attend_students_norm_item'][3],'check_value'=>round($studentsNorm[3],2).'%'),
					4=>array('item'=>$formdata['attend_students_norm_item'][4],'check_value'=>$studentsNorm[4]),
					5=>array('item'=>$formdata['attend_students_norm_item'][5],'check_value'=>$studentsNorm[5]),
					6=>array('item'=>$formdata['attend_students_norm_item'][6],'check_value'=>$studentsNorm[6]),
					7=>array('item'=>$formdata['attend_students_norm_item'][7],'check_value'=>$studentsNorm[7]),
					8=>array('item'=>$formdata['attend_students_norm_item'][8],'check_value'=>$studentsNorm[8])				
				),
				'attend_classroom_facilities'=>array('option'=>$formdata['attend_classroom_facilities_option'],'check_value'=>$formdata['classroom_facilities']),
				'attend_classroom_environmental'=>array('option'=>$formdata['classroom_environmental_option'],'check_value'=>$formdata['classroom_environmental']), */
				'attend_record' => array(
					0 => array('time' => $formdata['attend_record_time'], 'activity' => null, 'commentary' => $formdata['attend_record_content'])
				),
				'attend_img1' => $attend_img1_value,
				'attend_img2' => $attend_img2_value,
				'attend_img3' => $attend_img3_value,
			);
		}else if ($_SESSION[SESS_ASSESS]['cc_type'] ==3) {
			$param = array(
				'attend' => array(
					'class_id' => $class_id,
					'listen_id' => $_SESSION[SESS_USER_HOME]['id'],
					'type' => $type,
					// 'serial_no'=>$serial_no,
					'academic_year' => $academic_year, //学年
					'semester' => $semester, //学期
					'class_name' => $class_name,
					'class_type' => $class_type,
					'cc_type' => $_SESSION[SESS_ASSESS]['cc_type'],
					'teacher_name' => $teacher_name,
					'teacher_code' => $teacher_code,
					'title' => $title,
					'dept_name' => $dept_name,
					'age_groups' => $age_groups,
					'teachers_attribute' => $teachers_attribute,
					'listen_name' => $listen_name,
					'listen_time' => $formdata['listen_time'],
					'listen_address' => $listen_address,
					'course_units' => $course_units,
					'listen_class' => $listen_class,
					// 'classroom_facilities'=>$classroom_facilities_item,
					// 'classroom_environmental'=>$classroom_environmental_item,
					'advice' => $advice,
					'teaching_level_score' => $teachingLevel_count,
					'teaching_effect_score' => $teachingEffect_count,
					'status' => $status,
					// 0415新增总分 教学70%+学生30%
					'score' => ($teachingLevel_count  + $teachingEffect_count),
					// 0723新增听课类型
					'listen_type' => $listen_type
				),
				'attend3_teaching_content' => array(
					0 => array('key_index' => $formdata['attend3_teaching_index'][0], 'list_id' => $formdata['attend3_teaching_list_id'][0], 'content' => $formdata['attend3_teaching_content'][0], 'score' => $formdata['attend3_teaching_score'][0], 'get_score' => $teachingLevel[0]),
					1 => array('key_index' => $formdata['attend3_teaching_index'][1], 'list_id' => $formdata['attend3_teaching_list_id'][1], 'content' => $formdata['attend3_teaching_content'][1], 'score' => $formdata['attend3_teaching_score'][0], 'get_score' => $teachingLevel[1]),
					2 => array('key_index' => $formdata['attend3_teaching_index'][2], 'list_id' => $formdata['attend3_teaching_list_id'][2], 'content' => $formdata['attend3_teaching_content'][2], 'score' => $formdata['attend3_teaching_score'][0], 'get_score' => $teachingLevel[2]),
					3 => array('key_index' => $formdata['attend3_teaching_index'][3], 'list_id' => $formdata['attend3_teaching_list_id'][3], 'content' => $formdata['attend3_teaching_content'][3], 'score' => $formdata['attend3_teaching_score'][0], 'get_score' => $teachingLevel[3]),
				//	4 => array('key_index' => $formdata['attends_teaching_index'][4], 'list_id' => $formdata['attends_teaching_list_id'][4], 'content' => $formdata['attends_teaching_content'][4], 'score' => $formdata['attends_teaching_score'][0], 'get_score' => $teachingLevel[4])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_index'][2],'list_id'=>$formdata['attend_teaching_list_id'][2],'content'=>$formdata['attend_teaching_content'][2],'score'=>$formdata['attend_teaching_score'][0],'get_score'=>$teachingLevel[2])
				),
				'attend_teaching_level' => array(
					0 => array('item' => $formdata['attend_teaching_level_item'][0], 'remark' => $formdata['attend_teaching_level_remark'][0], 'is_check' => $teachingLevel_rank[0]),
					1 => array('item' => $formdata['attend_teaching_level_item'][1], 'remark' => $formdata['attend_teaching_level_remark'][1], 'is_check' => $teachingLevel_rank[1]),
					2 => array('item' => $formdata['attend_teaching_level_item'][2], 'remark' => $formdata['attend_teaching_level_remark'][2], 'is_check' => $teachingLevel_rank[2]),
					3 => array('item' => $formdata['attend_teaching_level_item'][3], 'remark' => $formdata['attend_teaching_level_remark'][3], 'is_check' => $teachingLevel_rank[3]),
				//	4 => array('item' => $formdata['attend_teaching_level_item'][4], 'remark' => $formdata['attend_teaching_level_remark'][4], 'is_check' => $teachingLevel_rank[4])
				),
				'attend_student_status' => array(
					0 => array('key_index' => $formdata['attend_student_status_index'][0], 'list_id' => $formdata['attend_student_status_list_id'][0], 'content' => $formdata['attend_student_status'][0], 'score' => $formdata['attend_student_status_score'][0], 'get_score' => $teachingEffect[0])
					// ,
					// 1=>array('key_index'=>$formdata['attend_student_status_index'][1],'list_id'=>$formdata['attend_student_status_list_id'][1],'content'=>$formdata['attend_student_status'][1],'score'=>$formdata['attend_student_status_score'][1],'get_score'=>$teachingEffect[1]),
					// 2=>array('key_index'=>$formdata['attend_student_status_index'][2],'list_id'=>$formdata['attend_student_status_list_id'][2],'content'=>$formdata['attend_student_status'][2],'score'=>$formdata['attend_student_status_score'][2],'get_score'=>$teachingEffect[2]),
					// 3=>array('key_index'=>$formdata['attend_student_status_index'][3],'list_id'=>$formdata['attend_student_status_list_id'][3],'content'=>$formdata['attend_student_status'][3],'score'=>$formdata['attend_student_status_score'][3],'get_score'=>$teachingEffect[3]),
					// 4=>array('key_index'=>$formdata['attend_student_status_index'][4],'list_id'=>$formdata['attend_student_status_list_id'][4],'content'=>$formdata['attend_student_status'][4],'score'=>$formdata['attend_student_status_score'][4],'get_score'=>$teachingEffect[4]),
					// 5=>array('key_index'=>$formdata['attend_student_status_index'][5],'list_id'=>$formdata['attend_student_status_list_id'][5],'content'=>$formdata['attend_student_status'][5],'score'=>$formdata['attend_student_status_score'][5],'get_score'=>$teachingEffect[5])
				),
				'attend_teaching_effect' => array(
					0 => array('item' => $formdata['attend_student_status_item'][0], 'remark' => $formdata['attend_student_status_remark'][0], 'is_check' => $teachingEffect_rank[0])
					// ,
					// 1=>array('item'=>$formdata['attend_student_status_item'][1],'remark'=>$formdata['attend_student_status_remark'][1],'is_check'=>$teachingEffect_rank[1]),
					// 2=>array('item'=>$formdata['attend_student_status_item'][2],'remark'=>$formdata['attend_student_status_remark'][2],'is_check'=>$teachingEffect_rank[2]),
					// 3=>array('item'=>$formdata['attend_student_status_item'][3],'remark'=>$formdata['attend_student_status_remark'][3],'is_check'=>$teachingEffect_rank[3]),
					// 4=>array('item'=>$formdata['attend_student_status_item'][4],'remark'=>$formdata['attend_student_status_remark'][4],'is_check'=>$teachingEffect_rank[4])
				),
				/* 'attend_teaching_readiness'=>array(
					0=>array('item'=>$formdata['attend_teaching_readiness_content'][0],'option'=>$formdata['attend_teaching_readiness_option'][0],'check_value'=>$teachingReadiness[0]),
					1=>array('item'=>$formdata['attend_teaching_readiness_content'][1],'option'=>$formdata['attend_teaching_readiness_option'][1],'check_value'=>$teachingReadiness[1]),
					2=>array('item'=>$formdata['attend_teaching_readiness_content'][2],'option'=>$formdata['attend_teaching_readiness_option'][2],'check_value'=>$teachingReadiness[2]),
					3=>array('item'=>$formdata['attend_teaching_readiness_content'][3],'option'=>$formdata['attend_teaching_readiness_option'][3],'check_value'=>$teachingReadiness[3]),
					4=>array('item'=>$formdata['attend_teaching_readiness_content'][4],'option'=>$formdata['attend_teaching_readiness_option'][4],'check_value'=>$teachingReadiness[4]),
					5=>array('item'=>$formdata['attend_teaching_readiness_content'][5],'option'=>$formdata['attend_teaching_readiness_option'][5],'check_value'=>$teachingReadiness[5]),
					6=>array('item'=>$formdata['attend_teaching_readiness_content'][6],'option'=>$formdata['attend_teaching_readiness_option'][6],'check_value'=>$teachingReadiness[6]),
					7=>array('item'=>$formdata['attend_teaching_readiness_content'][7],'option'=>$formdata['attend_teaching_readiness_option'][7],'check_value'=>$teachingReadiness[7]),
					8=>array('item'=>$formdata['attend_teaching_readiness_content'][8],'option'=>$formdata['attend_teaching_readiness_option'][8],'check_value'=>$teachingReadiness[8]),
					9=>array('item'=>$formdata['attend_teaching_readiness_content'][9],'option'=>$formdata['attend_teaching_readiness_option'][9],'check_value'=>$teachingReadiness[9]),
					10=>array('item'=>$formdata['attend_teaching_readiness_content'][10],'option'=>$formdata['attend_teaching_readiness_option'][10],'check_value'=>$teachingReadiness[10]),
					11=>array('item'=>$formdata['attend_teaching_readiness_content'][11],'option'=>$formdata['attend_teaching_readiness_option'][11],'check_value'=>$teachingReadiness[11])
				),
				'attend_students_norm'=>array(
					0=>array('item'=>$formdata['attend_students_norm_item'][0],'check_value'=>$studentsNorm[0]),
					1=>array('item'=>$formdata['attend_students_norm_item'][1],'check_value'=>$studentsNorm[1]),
					2=>array('item'=>$formdata['attend_students_norm_item'][2],'check_value'=>$studentsNorm[2]),
					3=>array('item'=>$formdata['attend_students_norm_item'][3],'check_value'=>round($studentsNorm[3],2).'%'),
					4=>array('item'=>$formdata['attend_students_norm_item'][4],'check_value'=>$studentsNorm[4]),
					5=>array('item'=>$formdata['attend_students_norm_item'][5],'check_value'=>$studentsNorm[5]),
					6=>array('item'=>$formdata['attend_students_norm_item'][6],'check_value'=>$studentsNorm[6]),
					7=>array('item'=>$formdata['attend_students_norm_item'][7],'check_value'=>$studentsNorm[7]),
					8=>array('item'=>$formdata['attend_students_norm_item'][8],'check_value'=>$studentsNorm[8])				
				),
				'attend_classroom_facilities'=>array('option'=>$formdata['attend_classroom_facilities_option'],'check_value'=>$formdata['classroom_facilities']),
				'attend_classroom_environmental'=>array('option'=>$formdata['classroom_environmental_option'],'check_value'=>$formdata['classroom_environmental']), */
				'attend_record' => array(
					0 => array('time' => $formdata['attend_record_time'], 'activity' => null, 'commentary' => $formdata['attend_record_content'])
				),
				'attend_img1' => $attend_img1_value,
				'attend_img2' => $attend_img2_value,
				'attend_img3' => $attend_img3_value,
			);
		}else if ($_SESSION[SESS_ASSESS]['cc_type'] ==4) {
			$param = array(
				'attend' => array(
					'class_id' => $class_id,
					'listen_id' => $_SESSION[SESS_USER_HOME]['id'],
					'type' => $type,
					// 'serial_no'=>$serial_no,
					'academic_year' => $academic_year, //学年
					'semester' => $semester, //学期
					'class_name' => $class_name,
					'class_type' => $class_type,
					'cc_type' => $_SESSION[SESS_ASSESS]['cc_type'],
					'teacher_name' => $teacher_name,
					'teacher_code' => $teacher_code,
					'title' => $title,
					'dept_name' => $dept_name,
					'age_groups' => $age_groups,
					'teachers_attribute' => $teachers_attribute,
					'listen_name' => $listen_name,
					'listen_time' => $formdata['listen_time'],
					'listen_address' => $listen_address,
					'course_units' => $course_units,
					'listen_class' => $listen_class,
					// 'classroom_facilities'=>$classroom_facilities_item,
					// 'classroom_environmental'=>$classroom_environmental_item,
					'advice' => $advice,
					'teaching_level_score' => $teachingLevel_count,
					'teaching_effect_score' => $teachingEffect_count,
					'status' => $status,
					// 0415新增总分 教学70%+学生30%
					'score' => ($teachingLevel_count + $teachingEffect_count ),
					// 0723新增听课类型
					'listen_type' => $listen_type
				),
				'attend4_teaching_content' => array(
					0 => array('key_index' => $formdata['attend4_teaching_index'][0], 'list_id' => $formdata['attend4_teaching_list_id'][0], 'content' => $formdata['attend4_teaching_content'][0], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[0]),
					1 => array('key_index' => $formdata['attend4_teaching_index'][1], 'list_id' => $formdata['attend4_teaching_list_id'][1], 'content' => $formdata['attend4_teaching_content'][1], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[1]),
					2 => array('key_index' => $formdata['attend4_teaching_index'][2], 'list_id' => $formdata['attend4_teaching_list_id'][2], 'content' => $formdata['attend4_teaching_content'][2], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[2]),
					3 => array('key_index' => $formdata['attend4_teaching_index'][3], 'list_id' => $formdata['attend4_teaching_list_id'][3], 'content' => $formdata['attend4_teaching_content'][3], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[3]),
					4 => array('key_index' => $formdata['attend4_teaching_index'][4], 'list_id' => $formdata['attend4_teaching_list_id'][4], 'content' => $formdata['attend4_teaching_content'][4], 'score' => $formdata['attend4_teaching_score'][0], 'get_score' => $teachingLevel[4])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_index'][2],'list_id'=>$formdata['attend_teaching_list_id'][2],'content'=>$formdata['attend_teaching_content'][2],'score'=>$formdata['attend_teaching_score'][0],'get_score'=>$teachingLevel[2])
				),
				'attend_teaching_level' => array(
					0 => array('item' => $formdata['attend_teaching_level_item'][0], 'remark' => $formdata['attend_teaching_level_remark'][0], 'is_check' => $teachingLevel_rank[0]),
					1 => array('item' => $formdata['attend_teaching_level_item'][1], 'remark' => $formdata['attend_teaching_level_remark'][1], 'is_check' => $teachingLevel_rank[1]),
					2 => array('item' => $formdata['attend_teaching_level_item'][2], 'remark' => $formdata['attend_teaching_level_remark'][2], 'is_check' => $teachingLevel_rank[2]),
					3 => array('item' => $formdata['attend_teaching_level_item'][3], 'remark' => $formdata['attend_teaching_level_remark'][3], 'is_check' => $teachingLevel_rank[3]),
				//	4 => array('item' => $formdata['attend_teaching_level_item'][4], 'remark' => $formdata['attend_teaching_level_remark'][4], 'is_check' => $teachingLevel_rank[4])
				),
				'attend_student_status' => array(
					0 => array('key_index' => $formdata['attend_student_status_index'][0], 'list_id' => $formdata['attend_student_status_list_id'][0], 'content' => $formdata['attend_student_status'][0], 'score' => $formdata['attend_student_status_score'][0], 'get_score' => $teachingEffect[0])
					// ,
					// 1=>array('key_index'=>$formdata['attend_student_status_index'][1],'list_id'=>$formdata['attend_student_status_list_id'][1],'content'=>$formdata['attend_student_status'][1],'score'=>$formdata['attend_student_status_score'][1],'get_score'=>$teachingEffect[1]),
					// 2=>array('key_index'=>$formdata['attend_student_status_index'][2],'list_id'=>$formdata['attend_student_status_list_id'][2],'content'=>$formdata['attend_student_status'][2],'score'=>$formdata['attend_student_status_score'][2],'get_score'=>$teachingEffect[2]),
					// 3=>array('key_index'=>$formdata['attend_student_status_index'][3],'list_id'=>$formdata['attend_student_status_list_id'][3],'content'=>$formdata['attend_student_status'][3],'score'=>$formdata['attend_student_status_score'][3],'get_score'=>$teachingEffect[3]),
					// 4=>array('key_index'=>$formdata['attend_student_status_index'][4],'list_id'=>$formdata['attend_student_status_list_id'][4],'content'=>$formdata['attend_student_status'][4],'score'=>$formdata['attend_student_status_score'][4],'get_score'=>$teachingEffect[4]),
					// 5=>array('key_index'=>$formdata['attend_student_status_index'][5],'list_id'=>$formdata['attend_student_status_list_id'][5],'content'=>$formdata['attend_student_status'][5],'score'=>$formdata['attend_student_status_score'][5],'get_score'=>$teachingEffect[5])
				),
				'attend_teaching_effect' => array(
					0 => array('item' => $formdata['attend_student_status_item'][0], 'remark' => $formdata['attend_student_status_remark'][0], 'is_check' => $teachingEffect_rank[0])
					// ,
					// 1=>array('item'=>$formdata['attend_student_status_item'][1],'remark'=>$formdata['attend_student_status_remark'][1],'is_check'=>$teachingEffect_rank[1]),
					// 2=>array('item'=>$formdata['attend_student_status_item'][2],'remark'=>$formdata['attend_student_status_remark'][2],'is_check'=>$teachingEffect_rank[2]),
					// 3=>array('item'=>$formdata['attend_student_status_item'][3],'remark'=>$formdata['attend_student_status_remark'][3],'is_check'=>$teachingEffect_rank[3]),
					// 4=>array('item'=>$formdata['attend_student_status_item'][4],'remark'=>$formdata['attend_student_status_remark'][4],'is_check'=>$teachingEffect_rank[4])
				),
				/* 'attend_teaching_readiness'=>array(
					0=>array('item'=>$formdata['attend_teaching_readiness_content'][0],'option'=>$formdata['attend_teaching_readiness_option'][0],'check_value'=>$teachingReadiness[0]),
					1=>array('item'=>$formdata['attend_teaching_readiness_content'][1],'option'=>$formdata['attend_teaching_readiness_option'][1],'check_value'=>$teachingReadiness[1]),
					2=>array('item'=>$formdata['attend_teaching_readiness_content'][2],'option'=>$formdata['attend_teaching_readiness_option'][2],'check_value'=>$teachingReadiness[2]),
					3=>array('item'=>$formdata['attend_teaching_readiness_content'][3],'option'=>$formdata['attend_teaching_readiness_option'][3],'check_value'=>$teachingReadiness[3]),
					4=>array('item'=>$formdata['attend_teaching_readiness_content'][4],'option'=>$formdata['attend_teaching_readiness_option'][4],'check_value'=>$teachingReadiness[4]),
					5=>array('item'=>$formdata['attend_teaching_readiness_content'][5],'option'=>$formdata['attend_teaching_readiness_option'][5],'check_value'=>$teachingReadiness[5]),
					6=>array('item'=>$formdata['attend_teaching_readiness_content'][6],'option'=>$formdata['attend_teaching_readiness_option'][6],'check_value'=>$teachingReadiness[6]),
					7=>array('item'=>$formdata['attend_teaching_readiness_content'][7],'option'=>$formdata['attend_teaching_readiness_option'][7],'check_value'=>$teachingReadiness[7]),
					8=>array('item'=>$formdata['attend_teaching_readiness_content'][8],'option'=>$formdata['attend_teaching_readiness_option'][8],'check_value'=>$teachingReadiness[8]),
					9=>array('item'=>$formdata['attend_teaching_readiness_content'][9],'option'=>$formdata['attend_teaching_readiness_option'][9],'check_value'=>$teachingReadiness[9]),
					10=>array('item'=>$formdata['attend_teaching_readiness_content'][10],'option'=>$formdata['attend_teaching_readiness_option'][10],'check_value'=>$teachingReadiness[10]),
					11=>array('item'=>$formdata['attend_teaching_readiness_content'][11],'option'=>$formdata['attend_teaching_readiness_option'][11],'check_value'=>$teachingReadiness[11])
				),
				'attend_students_norm'=>array(
					0=>array('item'=>$formdata['attend_students_norm_item'][0],'check_value'=>$studentsNorm[0]),
					1=>array('item'=>$formdata['attend_students_norm_item'][1],'check_value'=>$studentsNorm[1]),
					2=>array('item'=>$formdata['attend_students_norm_item'][2],'check_value'=>$studentsNorm[2]),
					3=>array('item'=>$formdata['attend_students_norm_item'][3],'check_value'=>round($studentsNorm[3],2).'%'),
					4=>array('item'=>$formdata['attend_students_norm_item'][4],'check_value'=>$studentsNorm[4]),
					5=>array('item'=>$formdata['attend_students_norm_item'][5],'check_value'=>$studentsNorm[5]),
					6=>array('item'=>$formdata['attend_students_norm_item'][6],'check_value'=>$studentsNorm[6]),
					7=>array('item'=>$formdata['attend_students_norm_item'][7],'check_value'=>$studentsNorm[7]),
					8=>array('item'=>$formdata['attend_students_norm_item'][8],'check_value'=>$studentsNorm[8])				
				),
				'attend_classroom_facilities'=>array('option'=>$formdata['attend_classroom_facilities_option'],'check_value'=>$formdata['classroom_facilities']),
				'attend_classroom_environmental'=>array('option'=>$formdata['classroom_environmental_option'],'check_value'=>$formdata['classroom_environmental']), */
				'attend_record' => array(
					0 => array('time' => $formdata['attend_record_time'], 'activity' => null, 'commentary' => $formdata['attend_record_content'])
				),
				'attend_img1' => $attend_img1_value,
				'attend_img2' => $attend_img2_value,
				'attend_img3' => $attend_img3_value,
			);
		} else {
			$param = array(
				'attend' => array(
					'class_id' => $class_id,
					'listen_id' => $_SESSION[SESS_USER_HOME]['id'],
					'type' => $type,
					// 'serial_no'=>$serial_no,
					'academic_year' => $academic_year, //学年
					'semester' => $semester, //学期
					'class_name' => $class_name,
					'class_type' => $class_type,
					'cc_type' => $_SESSION[SESS_ASSESS]['cc_type'],
					'teacher_name' => $teacher_name,
					'teacher_code' => $teacher_code,
					'title' => $title,
					'dept_name' => $dept_name,
					'age_groups' => $age_groups,
					'teachers_attribute' => $teachers_attribute,
					'listen_name' => $listen_name,
					'listen_time' => $formdata['listen_time'],
					'listen_address' => $listen_address,
					'course_units' => $course_units,
					'listen_class' => $listen_class,
					// 'classroom_facilities'=>$classroom_facilities_item,
					// 'classroom_environmental'=>$classroom_environmental_item,
					'advice' => $advice,
					'teaching_level_score' => $teachingLevel_count,
					'teaching_effect_score' => $teachingEffect_count,
					'status' => $status,
					// 0415新增总分 教学70%+学生30%
					'score' => ($teachingLevel_count + $teachingEffect_count ),
					// 0723新增听课类型
					'listen_type' => $listen_type
				),
				'attend_teaching_content' => array(
					0 => array('key_index' => $formdata['attend_teaching_index'][0], 'list_id' => $formdata['attend_teaching_list_id'][0], 'content' => $formdata['attend_teaching_content'][0], 'score' => $formdata['attend_teaching_score'][0], 'get_score' => $teachingLevel[0]),
					1 => array('key_index' => $formdata['attend_teaching_index'][1], 'list_id' => $formdata['attend_teaching_list_id'][1], 'content' => $formdata['attend_teaching_content'][1], 'score' => $formdata['attend_teaching_score'][0], 'get_score' => $teachingLevel[1])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_index'][2],'list_id'=>$formdata['attend_teaching_list_id'][2],'content'=>$formdata['attend_teaching_content'][2],'score'=>$formdata['attend_teaching_score'][0],'get_score'=>$teachingLevel[2])
				),
				'attend_teaching_implementation' => array(
					0 => array('key_index' => $formdata['attend_teaching_implementation_index'][0], 'list_id' => $formdata['attend_teaching_implementation_list_id'][0], 'content' => $formdata['attend_teaching_implementation_content'][0], 'score' => $formdata['attend_teaching_implementation_score'][0], 'get_score' => $teachingLevel[2]),
					1 => array('key_index' => $formdata['attend_teaching_implementation_index'][1], 'list_id' => $formdata['attend_teaching_implementation_list_id'][1], 'content' => $formdata['attend_teaching_implementation_content'][1], 'score' => $formdata['attend_teaching_implementation_score'][1], 'get_score' => $teachingLevel[3])
					// ,
					// 2=>array('key_index'=>$formdata['attend_teaching_implementation_index'][2],'list_id'=>$formdata['attend_teaching_implementation_list_id'][2],'content'=>$formdata['attend_teaching_implementation_content'][2],'score'=>$formdata['attend_teaching_implementation_score'][2],'get_score'=>$teachingLevel[5]),
					// 3=>array('key_index'=>$formdata['attend_teaching_implementation_index'][3],'list_id'=>$formdata['attend_teaching_implementation_list_id'][3],'content'=>$formdata['attend_teaching_implementation_content'][3],'score'=>$formdata['attend_teaching_implementation_score'][3],'get_score'=>$teachingLevel[6]),
					// 4=>array('key_index'=>$formdata['attend_teaching_implementation_index'][4],'list_id'=>$formdata['attend_teaching_implementation_list_id'][4],'content'=>$formdata['attend_teaching_implementation_content'][4],'score'=>$formdata['attend_teaching_implementation_score'][4],'get_score'=>$teachingLevel[7]),
					// 5=>array('key_index'=>$formdata['attend_teaching_implementation_index'][5],'list_id'=>$formdata['attend_teaching_implementation_list_id'][5],'content'=>$formdata['attend_teaching_implementation_content'][5],'score'=>$formdata['attend_teaching_implementation_score'][5],'get_score'=>$teachingLevel[8])	
				),
				'attend_teaching_level' => array(
					0 => array('item' => $formdata['attend_teaching_level_item'][0], 'remark' => $formdata['attend_teaching_level_remark'][0], 'is_check' => $teachingLevel_rank[0]),
					1 => array('item' => $formdata['attend_teaching_level_item'][1], 'remark' => $formdata['attend_teaching_level_remark'][1], 'is_check' => $teachingLevel_rank[1]),
					2 => array('item' => $formdata['attend_teaching_level_item'][2], 'remark' => $formdata['attend_teaching_level_remark'][2], 'is_check' => $teachingLevel_rank[2]),
					3 => array('item' => $formdata['attend_teaching_level_item'][3], 'remark' => $formdata['attend_teaching_level_remark'][3], 'is_check' => $teachingLevel_rank[3]),
					4 => array('item' => $formdata['attend_teaching_level_item'][4], 'remark' => $formdata['attend_teaching_level_remark'][4], 'is_check' => $teachingLevel_rank[4])
				),
				'attend_student_status' => array(
					0 => array('key_index' => $formdata['attend_student_status_index'][0], 'list_id' => $formdata['attend_student_status_list_id'][0], 'content' => $formdata['attend_student_status'][0], 'score' => $formdata['attend_student_status_score'][0], 'get_score' => $teachingEffect[0])
					// ,
					// 1=>array('key_index'=>$formdata['attend_student_status_index'][1],'list_id'=>$formdata['attend_student_status_list_id'][1],'content'=>$formdata['attend_student_status'][1],'score'=>$formdata['attend_student_status_score'][1],'get_score'=>$teachingEffect[1]),
					// 2=>array('key_index'=>$formdata['attend_student_status_index'][2],'list_id'=>$formdata['attend_student_status_list_id'][2],'content'=>$formdata['attend_student_status'][2],'score'=>$formdata['attend_student_status_score'][2],'get_score'=>$teachingEffect[2]),
					// 3=>array('key_index'=>$formdata['attend_student_status_index'][3],'list_id'=>$formdata['attend_student_status_list_id'][3],'content'=>$formdata['attend_student_status'][3],'score'=>$formdata['attend_student_status_score'][3],'get_score'=>$teachingEffect[3]),
					// 4=>array('key_index'=>$formdata['attend_student_status_index'][4],'list_id'=>$formdata['attend_student_status_list_id'][4],'content'=>$formdata['attend_student_status'][4],'score'=>$formdata['attend_student_status_score'][4],'get_score'=>$teachingEffect[4]),
					// 5=>array('key_index'=>$formdata['attend_student_status_index'][5],'list_id'=>$formdata['attend_student_status_list_id'][5],'content'=>$formdata['attend_student_status'][5],'score'=>$formdata['attend_student_status_score'][5],'get_score'=>$teachingEffect[5])
				),
				'attend_teaching_effect' => array(
					0 => array('item' => $formdata['attend_student_status_item'][0], 'remark' => $formdata['attend_student_status_remark'][0], 'is_check' => $teachingEffect_rank[0])
					// ,
					// 1=>array('item'=>$formdata['attend_student_status_item'][1],'remark'=>$formdata['attend_student_status_remark'][1],'is_check'=>$teachingEffect_rank[1]),
					// 2=>array('item'=>$formdata['attend_student_status_item'][2],'remark'=>$formdata['attend_student_status_remark'][2],'is_check'=>$teachingEffect_rank[2]),
					// 3=>array('item'=>$formdata['attend_student_status_item'][3],'remark'=>$formdata['attend_student_status_remark'][3],'is_check'=>$teachingEffect_rank[3]),
					// 4=>array('item'=>$formdata['attend_student_status_item'][4],'remark'=>$formdata['attend_student_status_remark'][4],'is_check'=>$teachingEffect_rank[4])
				),
				/* 'attend_teaching_readiness'=>array(
					0=>array('item'=>$formdata['attend_teaching_readiness_content'][0],'option'=>$formdata['attend_teaching_readiness_option'][0],'check_value'=>$teachingReadiness[0]),
					1=>array('item'=>$formdata['attend_teaching_readiness_content'][1],'option'=>$formdata['attend_teaching_readiness_option'][1],'check_value'=>$teachingReadiness[1]),
					2=>array('item'=>$formdata['attend_teaching_readiness_content'][2],'option'=>$formdata['attend_teaching_readiness_option'][2],'check_value'=>$teachingReadiness[2]),
					3=>array('item'=>$formdata['attend_teaching_readiness_content'][3],'option'=>$formdata['attend_teaching_readiness_option'][3],'check_value'=>$teachingReadiness[3]),
					4=>array('item'=>$formdata['attend_teaching_readiness_content'][4],'option'=>$formdata['attend_teaching_readiness_option'][4],'check_value'=>$teachingReadiness[4]),
					5=>array('item'=>$formdata['attend_teaching_readiness_content'][5],'option'=>$formdata['attend_teaching_readiness_option'][5],'check_value'=>$teachingReadiness[5]),
					6=>array('item'=>$formdata['attend_teaching_readiness_content'][6],'option'=>$formdata['attend_teaching_readiness_option'][6],'check_value'=>$teachingReadiness[6]),
					7=>array('item'=>$formdata['attend_teaching_readiness_content'][7],'option'=>$formdata['attend_teaching_readiness_option'][7],'check_value'=>$teachingReadiness[7]),
					8=>array('item'=>$formdata['attend_teaching_readiness_content'][8],'option'=>$formdata['attend_teaching_readiness_option'][8],'check_value'=>$teachingReadiness[8]),
					9=>array('item'=>$formdata['attend_teaching_readiness_content'][9],'option'=>$formdata['attend_teaching_readiness_option'][9],'check_value'=>$teachingReadiness[9]),
					10=>array('item'=>$formdata['attend_teaching_readiness_content'][10],'option'=>$formdata['attend_teaching_readiness_option'][10],'check_value'=>$teachingReadiness[10]),
					11=>array('item'=>$formdata['attend_teaching_readiness_content'][11],'option'=>$formdata['attend_teaching_readiness_option'][11],'check_value'=>$teachingReadiness[11])
				),
				'attend_students_norm'=>array(
					0=>array('item'=>$formdata['attend_students_norm_item'][0],'check_value'=>$studentsNorm[0]),
					1=>array('item'=>$formdata['attend_students_norm_item'][1],'check_value'=>$studentsNorm[1]),
					2=>array('item'=>$formdata['attend_students_norm_item'][2],'check_value'=>$studentsNorm[2]),
					3=>array('item'=>$formdata['attend_students_norm_item'][3],'check_value'=>round($studentsNorm[3],2).'%'),
					4=>array('item'=>$formdata['attend_students_norm_item'][4],'check_value'=>$studentsNorm[4]),
					5=>array('item'=>$formdata['attend_students_norm_item'][5],'check_value'=>$studentsNorm[5]),
					6=>array('item'=>$formdata['attend_students_norm_item'][6],'check_value'=>$studentsNorm[6]),
					7=>array('item'=>$formdata['attend_students_norm_item'][7],'check_value'=>$studentsNorm[7]),
					8=>array('item'=>$formdata['attend_students_norm_item'][8],'check_value'=>$studentsNorm[8])				
				),
				'attend_classroom_facilities'=>array('option'=>$formdata['attend_classroom_facilities_option'],'check_value'=>$formdata['classroom_facilities']),
				'attend_classroom_environmental'=>array('option'=>$formdata['classroom_environmental_option'],'check_value'=>$formdata['classroom_environmental']), */
				'attend_record' => array(
					0 => array('time' => $formdata['attend_record_time'], 'activity' => null, 'commentary' => $formdata['attend_record_content'])
				),
				'attend_img1' => $attend_img1_value,
				'attend_img2' => $attend_img2_value,
				'attend_img3' => $attend_img3_value,
			);
		}

		// pri($param);
		// exit;
		if ($is_add == 0) {
			$result = $this->attend_service->saveAttend($param);
		} else {
			$result = $this->attend_service->saveAttend($param, $is_add); //1.id,2,
		}
		unset($_SESSION[SESS_ASSESS]);
		if ($formdata['save'] == AttendStatus::Submit[XPHEnum::Value]) {
			$this->Attend_model->update(array('id' => $attend_id, 'back_time' => null)); //清空回退时间
			exit(retJson('提交成功！', true, $result));
		} else {
			exit(retJson('保存成功！', true, $result));
		}
	}

	function SubmittedAssess()
	{
		$connar['where'] = $this->sqlEscape("listen_id=?? and status=??", array($_SESSION[SESS_USER_HOME]['id'], AttendStatus::Submit[XPHEnum::Value]));
		$connar['orderby'] = 'created desc';
		$result['detail'] = $this->Attend_model->get_list_full($connar);
		foreach ($result['detail'] as $k => $v) {
			$result['detail'][$k]['type_char'] = (new AttendType)->show($v['type']);
		}
		// var_dump($result);
		$this->load->view("home/submitted_assess", $result);
	}

	function SaveAssess()
	{
		$connar['where'] = $this->sqlEscape("listen_id=?? and status=??", array($_SESSION[SESS_USER_HOME]['id'], AttendStatus::Save[XPHEnum::Value]));
		$connar['orderby'] = 'back_time desc,created desc';
		$result['detail'] = $this->Attend_model->get_list_full($connar);
		foreach ($result['detail'] as $k => $v) {
			$result['detail'][$k]['type_char'] = (new AttendType)->show($v['type']);
			if ($v['course_units'] == '' || $v['listen_time'] == '' || $v['class_name'] == '' || $v['teacher_name'] == '' || $v['dept_name'] == '' || $v['title'] == '' || $v['teachers_attribute'] == '' || $v['class_type'] == '' || $v['listen_class'] == '' || $v['listen_address'] == '' || $v['type'] == '' || $v['listen_type'] == '' || $v['teaching_level_score'] == '0' || $v['teaching_effect_score'] == '0' || $v['score'] == '0') {
				$result['detail'][$k]['is_finish'] = 0;
			} else {
				$result['detail'][$k]['is_finish'] = 1;
			}
		}
		unset($_SESSION[SESS_ASSESS]); //清除session缓存
		// var_dump($result);
		$this->load->view("home/saved_assess", $result);
	}


	//督导批量提交听课
	function moreSubmit()
	{

		if (!isset($_POST['id'])) {
			exit(retJson('参数错误', false));
		}
		$ids =  implode(',', $_POST['id']);

		//听课 
		$connar['where'] = "id in(" . $ids . ")";
		$attendArr = $this->Attend_model->get_list_full($connar);

		foreach ($attendArr as $key => $value) {
			if ($value['course_units'] == '' || $value['listen_time'] == '' || $value['listen_time'] == '0' || $value['class_name'] == '' || $value['teacher_name'] == '' || $value['dept_name'] == '' || $value['title'] == '' || $value['teachers_attribute'] == '' || $value['class_type'] == '' || $value['listen_class'] == '' || $value['listen_address'] == '' || $value['type'] == '' || $value['listen_type'] == '' || $value['teaching_level_score'] == '0' || $value['teaching_effect_score'] == '0' || $value['score'] == '0') {
				$Error['error'] = 2;
				exit(retJson("未填写完整的数据无法提交", false, $Error));
			} else {
				//教师听课无法提交
				if ($value['type'] == AttendType::Teacher[XPHEnum::Value]) {
					exit(retJson('教师听课无法提交', false));
				} else {

					// 批量提交未提交的听课记录
					if ($value['status'] == AttendStatus::Save[XPHEnum::Value]) {
						$data['id'] = $value['id'];
						$data['status'] =  AttendStatus::Submit[XPHEnum::Value];
						$data['back_time'] =  null;
						$this->Attend_model->update($data, 'id');
					} else {
						$Error['error'] = 2;
						exit(retJson("已提交的无需再提交", false, $Error));
					}
				}
			}
		}

		exit(retJson("提交成功.", true));
	}


	function base64EncodeImage($image_file)
	{
		$base64_image = '';
		$image_info = getimagesize($image_file);
		$image_data = fread(fopen($image_file, 'r'), filesize($image_file));
		$base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data));
		return $base64_image;
	}

	function delAssess()
	{
		$attend_id = $_POST['attend_id'];
		$data = $this->Attend_model->get_single(array('id' => $attend_id));
		if ($data['status'] == AttendStatus::Submit[XPHEnum::Value]) {
			exit(retJson('已提交无法删除！', false));
		}
		$this->Attend_model->update(array("id" => $attend_id, "status" => AttendStatus::Deleted[XPHEnum::Value]));
		exit(retJson("删除成功！", true));
	}
	function teachweek($date)
	{
		$timestamp = strtotime($date);
		if (date('m', $timestamp) >= 9) {
			return date('W', $timestamp) - 35;
		} elseif (date('m', $timestamp) <= 2) {
			return date('W', $timestamp) + 18;
		} else {
			return date('W', $timestamp) - 7;
		}
	}

	// 更新表数据教师工号
	function  updateTeacherCode()
	{
		$connar['items'] = 'db_attend.id attend_id,db_admin.usercode';
		$connar['join'] = array('db_admin', 'db_admin.username=db_attend.teacher_name');
		$list = $this->Attend_model->get_list_full($connar);
		// var_dump($list);
		foreach ($list as $k => $v) {
			$update = array(
				'id' => $v['attend_id'],
				'teacher_code' => $v['usercode']
			);
			$this->Attend_model->update($update);
		}
	}

	function clearSession()
	{
		unset($_SESSION[SESS_ASSESS]);
		exit(retJson("清除成功", true));
	}

	// 保存听课记录session
	function saveText()
	{
		$_SESSION[SESS_ASSESS]['record'] = $_POST['record'];
		$_SESSION[SESS_ASSESS]['advice'] = $_POST['advice'];

		exit(retJson("保存成功", true));
	}

	//保存学生常态
	function saveText1()
	{
		$_SESSION[SESS_ASSESS]['img1'] = isset($_POST['img1']) ? $_POST['img1'] : array(); //$this->NOTXSS_POST['img'];
		$_SESSION[SESS_ASSESS]['img2'] = isset($_POST['img2']) ? $_POST['img2'] : array(); //$this->NOTXSS_POST['img'];
		$_SESSION[SESS_ASSESS]['img3'] = isset($_POST['img3']) ? $_POST['img3'] : array(); //$this->NOTXSS_POST['img'];
		exit(retJson("保存成功", true));
	}
}
